home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / Updates / HD-Installer / -WHDLoad- / WHDLoad_dev / Src / imager-examples / bloodmoney.imager.asm next >
Assembly Source File  |  2000-05-08  |  7KB  |  330 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Program.    bloodmoney.imager.asm
  3. ;  :Contents.    Imager for "Blood Money" (Psycnosis)
  4. ;  :Author.    WEPL
  5. ;  :Version.    $Id: bloodmoney.imager.asm 1.3 1998/06/27 23:48:35 jah Exp jah $
  6. ;  :History.    21.10.97 first try
  7. ;  :Requires.    -
  8. ;  :Copyright.    Public Domain
  9. ;  :Language.    68000 Assembler
  10. ;  :Translator.    Barfly V1.131
  11. ;  :To Do.
  12. ;---------------------------------------------------------------------------*
  13. ;
  14. ;    Disk format:
  15. ;    Disk 1:        0    standard
  16. ;            1    unformatted
  17. ;            2-159    6200 bytes sync=4489
  18. ;    Disk 2:        0-1    unformatted
  19. ;            2-159    6200 bytes sync=4489
  20. ;
  21. ;    Image format:
  22. ;    Disk 1,2    tracks 2-158 (even ones)  489800
  23. ;            tracks 3-159 (odd ones) + 489800
  24. ;                        = 979600
  25. ;
  26. ;---------------------------------------------------------------------------*
  27.  
  28.     INCDIR    Includes:
  29.     INCLUDE    devices/trackdisk.i
  30.     INCLUDE    intuition/intuition.i
  31.     INCLUDE    utility/tagitem.i
  32.     INCLUDE    lvo/exec.i
  33.     INCLUDE    lvo/intuition.i
  34.     INCLUDE    patcher.i
  35.  
  36.     IFD BARFLY
  37.     OUTPUT    "C:Parameter/bloodmoney.imager"
  38.     BOPT    O+ OG+            ;enable optimizing
  39.     BOPT    ODd- ODe-        ;disable mul optimizing
  40.     ENDC
  41.  
  42. ;======================================================================
  43.  
  44.         moveq    #-1,d0
  45.         rts
  46.         dc.l    _Table
  47.         dc.l    "PTCH"
  48.  
  49. ;======================================================================
  50.  
  51. _Table        dc.l    PCH_ADAPTOR,.adname        ;name adaptor
  52.         dc.l    PCH_NAME,.name            ;description of parameter
  53.         dc.l    PCH_FILECOUNT,2            ;number of cycles
  54.         dc.l    PCH_FILENAME,.filenamearray    ;file names
  55.         dc.l    PCH_DATALENGTH,_lengtharray    ;file lengths
  56.         dc.l    PCH_DISKNAME,.disknamearray    ;disk names
  57.         dc.l    PCH_SPECIAL,.specialarray    ;functions
  58.         dc.l    PCH_STATE,.statearray        ;state texts
  59.         dc.l    PCH_MINVERSION,.patcherver    ;minimum patcher version required
  60.         dc.l    PCH_INIT,_Init            ;init routine
  61.         dc.l    PCH_FINISH,_Finish        ;finish routine
  62.         dc.l    TAG_DONE
  63.  
  64. .filenamearray    dc.l    .f1
  65.         dc.l    .f2
  66. .disknamearray    dc.l    .d
  67.         dc.l    .d
  68. .specialarray    dc.l    _Special
  69.         dc.l    _Special
  70. .statearray    dc.l    .insertdisk
  71.         dc.l    .insertdisk
  72.  
  73. .f1        dc.b    "Disk.1",0
  74. .f2        dc.b    "Disk.2",0
  75. .d        dc.b    "BloodMoney",0
  76.  
  77. .adname        dc.b    "Done by Wepl.",0
  78. .name        dc.b    "Blood Money, Diskimager for HD-Install",0
  79. .patcherver    dc.b    "V1.04"
  80. .insertdisk    dc.b    'Please insert your original writepro-',10
  81.         dc.b    'tected disk in the source drive.',0
  82.     IFD BARFLY
  83.         dc.b    "$VER: "
  84.     DOSCMD    "WDate >T:date"
  85.     INCBIN    "T:date"
  86.         dc.b    0
  87.     ENDC
  88.     EVEN
  89.  
  90. ;======================================================================
  91.  
  92. _Init        moveq    #0,d0                ;source drive
  93.         move.l    PTB_INHIBITDRIVE(a5),a0        ;inhibit drive
  94.         jsr    (a0)
  95.         tst.l    d0
  96.         bne    .error
  97.         
  98.         moveq    #0,d0                ;source drive
  99.         move.l    PTB_OPENDEVICE(a5),a0        ;open source device
  100.         jsr    (a0)
  101.         tst.l    d0
  102.         bne    .error
  103.         rts
  104.  
  105. .error        bsr    _Finish
  106.         moveq    #-1,d0
  107.         rts
  108.  
  109. ;======================================================================
  110.  
  111. _Finish        moveq    #0,d0                ;source drive
  112.         move.l    PTB_ENABLEDRIVE(a5),a0        ;deinhibit drive
  113.         jmp    (a0)
  114.  
  115. ;======================================================================
  116.  
  117. RAWREADLEN    = $7c00
  118. BYTESPERTRACK    = $1838
  119. SYNC        = $4489
  120.  
  121. ;======================================================================
  122.  
  123. _lengtharray    dc.l    BYTESPERTRACK*158
  124.         dc.l    BYTESPERTRACK*158
  125. _starttrack    dc.b    2
  126.         dc.b    2
  127. _counttrack    dc.b    158
  128.         dc.b    158
  129.  
  130. ;======================================================================
  131.  
  132. _Special    moveq    #-1,d7                ;D7 = return code (default=error)
  133.  
  134.         bsr    _InsertDisk
  135.         tst.l    d0
  136.         beq    .nodisk
  137.         
  138.     ;check for disk in drive
  139.         move.l    (PTB_DEVICESOURCEPTR,a5),a1
  140.         move.w    #TD_CHANGESTATE,(IO_COMMAND,a1)
  141.         move.l    (4).w,a6
  142.         jsr    (_LVODoIO,a6)
  143.         tst.l    (IO_ACTUAL,a1)
  144.         bne    .nodisk
  145.  
  146.         moveq    #0,d2                ;D2 = start/actual track
  147.         move.b    (_starttrack,pc,d6.w),d2
  148.         moveq    #0,d3                ;D3 = amount of tracks
  149.         move.b    (_counttrack,pc,d6.w),d3
  150.         move.l    (PTB_ADDRESSOFFILE,a5),a2    ;A2 = file address
  151.  
  152. .next        moveq    #5-1,d6                ;D6 = retries decoding
  153. .decretry    moveq    #5-1,d5                ;D5 = retries rawread
  154. .tdretry    move.l    (PTB_DEVICESOURCEPTR,a5),a1
  155.         move.l    (PTB_SPACE,a5),(IO_DATA,a1)    ;track is to load in ptb_space
  156.         move.l    #RAWREADLEN,(IO_LENGTH,a1)    ;double length of track to decode the index-sync-read data
  157.         move.l    d2,(IO_OFFSET,a1)
  158.         move.w    #TD_RAWREAD,(IO_COMMAND,a1)
  159.         move.b    #IOTDB_INDEXSYNC,(IO_FLAGS,a1)
  160.         move.l    (4).w,a6
  161.         jsr    (_LVODoIO,a6)
  162.         tst.l    d0
  163.         beq    .tdok
  164.         dbf    d5,.tdretry
  165.         bra    .tderr
  166. .tdok
  167.         move.l    (PTB_SPACE,a5),a0        ;source
  168.         move.l    a2,a1                ;destination
  169.         bsr    _Decode
  170.         tst.l    d0
  171.         beq    .decok
  172.         dbf    d6,.decretry
  173.         bra    .decerr
  174. .decok
  175.         add.l    #BYTESPERTRACK,a2
  176.         addq.w    #2,d2                ;two track further
  177.         cmp.w    #160,d2
  178.         bne    .1
  179.         moveq    #3,d2
  180. .1        subq.w    #1,d3                ;one track less
  181.         bne    .next
  182.  
  183.         moveq    #0,d7                ;return code
  184.         bra    .motoff
  185. .decerr
  186. .tderr        bsr    _ReadError
  187.  
  188.     ;switch motor off
  189. .motoff        move.l    (PTB_DEVICESOURCEPTR,a5),a1
  190.         clr.l    (IO_LENGTH,a1)
  191.         move.w    #TD_MOTOR,(IO_COMMAND,a1)
  192.         move.l    (4).w,a6
  193.         jsr    (_LVODoIO,a6)
  194. .nodisk
  195.     ;enable drive
  196.         tst.b    d7
  197.         beq    .quit
  198.         bsr    _Finish
  199.         
  200. .quit        move.l    d7,d0
  201.         rts
  202.  
  203. ;======================================================================
  204. ; IN:    A0 = raw
  205. ;    A1 = dest
  206. ; OUT:    D0 = error
  207.  
  208. GetW    MACRO
  209.         cmp.l    a0,a5
  210.         bls    .error
  211.         move.l    (a0),\1
  212.         lsr.l    d5,\1
  213.     ENDM
  214. GetWI    MACRO
  215.         GetW    \1
  216.         addq.l    #2,a0
  217.     ENDM
  218.  
  219. _Decode        movem.l    d1-a6,-(a7)
  220.         move.l    a7,a6            ;A6 = return stack
  221.         lea    (RAWREADLEN,a0),a5    ;A5 = end of raw data
  222.  
  223.         lsr.w    #1,d2            ;Not track But cylinder !
  224.  
  225.     ;find sync
  226. .sync1        moveq    #16-1,d5        ;D5 = shift count
  227. .sync2        GetW    d0
  228.         cmp.w    #SYNC,d0
  229.         beq    .sync3
  230. .sync_retry    dbf    d5,.sync2
  231.         addq.l    #2,a0
  232.         bra    .sync1
  233.  
  234. .sync3        movem.l    a0/a1,-(a7)        ;save this point for new try
  235.  
  236. .sync4        addq.l    #2,a0
  237.         GetW    d0
  238.         cmp.w    #SYNC,d0
  239.         beq    .sync4
  240.         
  241.     ;now stuff from original
  242.         GetWI    d0
  243.         cmp.w    #$552a,d0
  244.         bne    .fail
  245.         GetWI    d0
  246.         cmp.w    #$2a55,d0
  247.         bne    .fail
  248.         
  249.         moveq    #0,d6
  250.         move.w    #$c1b,d7
  251. .dec        GetWI    d0
  252.         GetWI    d1
  253.         lsl.w    #1,d0
  254.         and.w    #$aaaa,d0
  255.         and.w    #$5555,d1
  256.         or.w    d1,d0
  257.         eor.w    d2,d0            ;actual cylinder !
  258.         move.w    d0,(a1)+
  259.         add.w    d0,d6
  260.         dbf    d7,.dec
  261.  
  262.         GetWI    d0
  263.         GetW    d1
  264.         lsl.w    #1,d0
  265.         and.w    #$aaaa,d0
  266.         and.w    #$5555,d1
  267.         or.w    d1,d0
  268.         eor.w    d2,d0            ;actual cylinder !
  269.         cmp.w    d0,d6
  270.         beq    .success
  271.  
  272. .fail        movem.l    (a7)+,a0/a1
  273.         bra    .sync_retry        ;try again
  274.  
  275. .success    moveq    #0,d0
  276. .quit        move.l    a6,a7
  277.         movem.l    (a7)+,d1-a6
  278.         rts
  279. .error        moveq    #-1,d0
  280.         bra    .quit
  281.  
  282. ;======================================================================
  283.  
  284. _InsertDisk    sub.l    a0,a0                ;window
  285.         pea    (.gadgets)
  286.         pea    (.text)
  287.         pea    (.titel)
  288.         clr.l    -(a7)
  289.         pea    (EasyStruct_SIZEOF)
  290.         move.l    a7,a1                ;easyStruct
  291.         sub.l    a2,a2                ;IDCMP_ptr
  292.         move.l    d6,-(a7)
  293.         addq.l    #1,(a7)
  294.         move.l    a7,a3                ;Args
  295.         move.l    (PTB_INTUITIONBASE,a5),a6
  296.         jsr    (_LVOEasyRequestArgs,a6)
  297.         add.w    #6*4,a7
  298.         rts
  299.  
  300. .titel        dc.b    "Insert Disk",0
  301. .text        dc.b    "Insert your orginal disk %ld",10
  302.         dc.b    "into the source drive !",0
  303. .gadgets    dc.b    "OK|Cancel",0,0
  304.  
  305. ;======================================================================
  306.  
  307. _ReadError    sub.l    a0,a0                ;window
  308.         pea    (.gadgets)
  309.         pea    (.text)
  310.         pea    (.titel)
  311.         clr.l    -(a7)
  312.         pea    (EasyStruct_SIZEOF)
  313.         move.l    a7,a1                ;easyStruct
  314.         sub.l    a2,a2                ;IDCMP_ptr
  315.         move.l    d2,-(a7)
  316.         move.l    a7,a3                ;Args
  317.         move.l    (PTB_INTUITIONBASE,a5),a6
  318.         jsr    (_LVOEasyRequestArgs,a6)
  319.         add.w    #6*4,a7
  320.         rts
  321.  
  322. .titel        dc.b    "Error",0
  323. .text        dc.b    "Can't read track %ld",0
  324. .gadgets    dc.b    "OK",0
  325.  
  326. ;======================================================================
  327.  
  328.     END
  329.  
  330.